系統上很簡單 application透過config server連到指定的Github讀取"遵照命名規則"的檔案
這篇來看一些設定的部分
當然可以指向自己設定的Github(或是檔案位址),而且不用重編譯Java
直接用notepad++開啟設定檔 configserver\src\main\resources\application.yml
server:
port: 8888
management:
context-path: /admin
logging:
level:
com.netflix.discovery: 'OFF'
org.springframework.cloud: 'DEBUG'
eureka:
instance:
leaseRenewalIntervalInSeconds: 10
statusPageUrlPath: /admin/info
healthCheckUrlPath: /admin/health
spring:
cloud:
config:
server:
git:
uri: https://github.com/steeltoeoss/config-repo
---
spring:
profiles: cloud
eureka:
password: password
instance:
hostname: ${vcap.application.uris[0]}
nonSecurePort: 80
client:
serviceUrl:
defaultZone: ${vcap.services.${PREFIX:}eureka.credentials.uri:http://user:${eureka.password:}@${PREFIX:}eureka.${application.domain:cfapps.io}}/eureka/
更改localhost port的設定就在 port: 8888
更改遠端的Github repo就處理這行 uri: https://github.com/steeltoeoss/config-repo
關於這個問題就要先來看一下sample裡面的設定
SimpleCloudFoundry\appsettings.json
{
"spring": {
"application": {
"name": "bar"
},
"cloud": {
"config": {
"uri": "http://localhost:8888",
"validate_certificates": false
}
}
},
"Logging": {
"IncludeScopes": false,
"LogLevel": {
"Default": "Warning"
}
}
}
舉例來說
注意 "name":"bar" 代表這個application 名字是bar,所以會去讀github repo裡的bar.properties
若為"name":"foo"就會去讀foo.properties, 在加上環境變數ASPNETCORE_ENVIRONMENT為development,就會多讀foo-development.properties
config server的位址則是以下
"cloud": {
"config": {
"uri": "http://localhost:8888"
如果在config server的application.yml有改設定,這邊記得也要更改
專案底下有一個 SimpleCloudFoundry\config-server.json
雖然裡面也有類似組態Github repo的位址,但config-server.json不適用於Config Server,而是給cloud Foundry使用
´´´
{
"git" : {
"uri": "https://github.com/spring-cloud-samples/config-repo"
}
}
´´